<template>
	<view class="navTabBox">
		<view class="longTab">
			<scroll-view class="scroll" scroll-x="true" style="white-space: nowrap; display: flex;" scroll-with-animation :scroll-left="tabLeft" show-scrollbar="true">
				<view class="longItem" :style='"width:"+isWidth+"px"' :data-index="index" :class="index===tabClick?'click':''" v-for="(item,index) in tabTitle" :key="index" :id="'id'+index" @click="longClick(index,item.goods_category_id,item.pid)">
				{{item.cate_name}}
					<view class="remark" :class="index===tabClick?'remarkClick':''">
						{{item.info}}
					</view>
				</view>
				<view class="underlineBox" :style='"transform:translateX("+isLeft+"px);width:"+isWidth+"px"'>
					<view class="underline bg-color-red"></view>
				</view>
			</scroll-view>
		</view>
		
<!-- 		<view @click="showPopup" class="longTabRight">
			<view class="firewood">
				筛选
			</view>
			<view class="firewoodBot">
				看你喜欢
			</view>
		</view> -->
		
		<view v-if="showFirewood" class="popupBox">
			<view v-for="(item,index) in popupBoxList" :key="index" @click="checkClass(index)" :class="[{'checkStyle':showCheckStyle == index},  'popupTop']">
				{{ item.text }}
			</view>
			<view class="triangle">
			</view>
		</view>
	<!-- 	<view class="child-box" v-if="tabClick>0 && tabTitle[tabClick].children.length>0">
			<scroll-view scroll-x="true" style="white-space: nowrap; display: flex;align-items: center; height: 100%;" scroll-with-animation :scroll-left="tabLeft" show-scrollbar="false">
				<view class="wrapper">
					<view v-for="(item,index) in tabTitle[tabClick].children" class="child-item" :class="{on:index == childIndex}" @click="childTab(tabClick,index)">
						<image :src="item.pic" mode=""></image>
						<view class="txt">{{item.cate_name}}</view>
					</view>
				</view>
			</scroll-view>
		</view> -->
	</view>
</template>

<script>
	let app = getApp();
	export default {
		name: 'navTab',
		props: {
			tabTitle: {
				type: Array,
				default: []
			}

		},
		data() {
			return {
				tabClick: 0, //导航栏被点击
				isLeft: 0, //导航栏下划线位置
				isWidth: 0, //每个导航栏占位
				tabLeft:0,
				swiperIndex:0,
				childIndex:0,
				childID:0,
				showFirewood:false, // 控制筛选显示
				showCheckStyle:0, // 筛选选中样式
				popupBoxList:[
					{
						text:'默认'
					},
					{
						text:'佣金高'
					}
				]
			};
		},
		created() {
			var that = this
			// 获取设备宽度
			uni.getSystemInfo({
				success(e) {
					that.isWidth = e.windowWidth / 5 
				}
			})
		},
		methods: {
			// 点击筛选
			showPopup() {
				this.showFirewood = !this.showFirewood
			},
			// 选中的筛选
			checkClass(index) {
				this.showCheckStyle = index
				if(this.showCheckStyle == 0) {
					this.$emit('changeTab', {
						pid:'default'
					});
				}else {
					this.$emit('changeTab', {
						pid:'commission'
					});
				}
				// if(this.showCheckStyle) {
				// 	this.$emit('changeTab', '0');
				// }else {
				// 	this.$emit('changeTab', '1');
				// }
			},
			// 导航栏点击
			longClick(index,id,fid){
				app.globalData.fid = fid;
				this.childIndex = 0;
				if(this.tabTitle.length>5){
					var tempIndex = index - 2;
					tempIndex = tempIndex<=0 ? 0 : tempIndex;
					this.tabLeft = (index-2) * this.isWidth //设置下划线位置
				}
				this.tabClick = index //设置导航点击了哪一个
				this.isLeft = index * this.isWidth //设置下划线位置
				
				// let obj = {
				// 	type:'big',  //大标题
				// 	index:index
				// }
				let obj = {
					index:index,
					pid:id//自己的id
				}
				
				this.parentEmit(obj);
				
				// this.$parent.currentTab = index //设置swiper的第几页
			},
			// 导航子类点击
			// childTab(tabClick,index){
			// 	this.childIndex = index
			// 	let obj = {
			// 		parentIndex:tabClick,
			// 		childIndex:index,
			// 		type:'small' //小标题
			// 	}
			// 	this.parentEmit(obj)
			// }
			parentEmit(obj){
				this.$emit('changeTab', obj);
			}
		}
	}
</script>

<style lang="scss">
	.navTabBox {
		position: relative;
		width: 100%;
		// color: rgba(255, 255, 255, 1);
		.click {
			color: white;
		}
		.longTabRight {
			position: absolute;
			top: 26rpx;
			right: 25rpx;
			text-align: center;
			box-shadow: -10rpx 0rpx 15rpx -10rpx #C8C7CC;
			.firewood {
				margin-bottom: 16rpx;
			}
			.firewoodBot {
				font-size: 18rpx;
				color: #C8C7CC;
				margin-left: 28rpx;
			}
		}
		.popupBox {
			position: absolute;
			top: 130rpx;
			right: 60rpx;
			box-shadow: 0 3rpx 18rpx 0 #C8C7CC;
			line-height: 60rpx;
			border-radius: 10rpx;
			font-size: 26rpx;
			background-color: #FFFFFF;
			.popupTop {
				width: 200rpx;
				height: 60rpx;
				border-bottom: 0.5rpx solid #C8C7CC;
				padding-left: 20rpx;
			}
			.popupBot {
				width: 200rpx;
				height: 60rpx;
				padding-left: 20rpx;
			}
			.triangle {
				position: absolute;
				top: -10rpx;
				right: 20rpx;
				transform:rotate(45deg);
				-ms-transform:rotate(45deg); 	/* IE 9 */
				-moz-transform:rotate(45deg); 	/* Firefox */
				-webkit-transform:rotate(45deg); /* Safari 和 Chrome */
				-o-transform:rotate(45deg); 	/* Opera */
				width: 30rpx;
				height: 30rpx;
				background-color: #FFFFFF;
			}
			.checkStyle {
				color: #E93323;
			}
		}
		.longTab {
			width: 100%;
			/* #ifdef H5 */
			padding-bottom: 20rpx;
			/* #endif */
			/* #ifdef MP */
			padding-top: 12rpx;
			padding-bottom: 12rpx;
			/* #endif */
			.scroll {
				width: 100%;
				.longItem{ 
					height: 50upx; 
					display: inline-block;
					line-height: 50upx;
					text-align: center;
					font-size: 28rpx;
					color: #333333;
					.remark {
						font-size: 18rpx;
						color: #C8C7CC;
					}
					.remarkClick {
						color: #E93323;
					}
					&.click{
						font-weight: bold;
						font-size: 30rpx;
						color: #E93323;
					}
				}
				.underlineBox {
					height: 3px;
					width: 20%;
					display: flex;
					align-content: center;
					justify-content: center;
					transition: .5s;
					.underline {
						width: 33rpx;
						height: 4rpx;
					}
				}
			}
		}
		
	}
	.child-box{
		width: 100%;
		position: relative;
		// height: 152rpx;
		background-color: #fff;
		/* #ifdef H5 */
		box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.02);
		/* #endif */
		/* #ifdef MP */
		box-shadow: 0 2rpx 3rpx 1rpx #f9f9f9;
		/* #endif */
		
		.wrapper{
			display: flex;
			align-items: center;
			padding: 20rpx 0;
			background: #fff;
			/* #ifdef H5 */
			//box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.06);
			/* #endif */
		}
		.child-item{
			flex-shrink: 0;
			width:140rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			margin-left: 10rpx;
			image{
				width: 90rpx;
				height: 90rpx;
				border-radius: 50%;
			}
			.txt{
				font-size: 24rpx;
				color: #282828;
				text-align: center;
				margin-top: 10rpx;
			}
			&.on{
				image{
					border: 1px solid $theme-color-opacity;
				}
				.txt{
					color: $theme-color;
				}
			}
		}
	}
</style>
